3 Programming Concepts and Conventions

1.Composer install magento 2

composer create-project –repository-url=https://repo.magento.com/magento/project-enterprise-edition <installation directory name>

2. Service contracts

A service contract is a set of PHP interfaces that is defined by a module. This contract comprises data interfaces and service interfaces.

Data interfaces define various functions, such as validation, entity information,search related functions, and so on. They are defined within the Api/Data directory of an individual module.

Example:

BlockInterface.php

BlockSearchResultsInterface.php

PageInterface.php

PageSearchResultsInterface.php

Service interfaces are the ones that include management, repository, and metadata

interfaces. These interfaces are defined directly within the module’s Api directory.

Looking back at the Magento Cms module, its vendor/magento/module-cms/Api/

directory has two service interfaces, which are defined as follows:

BlockRepositoryInterface.php

PageRepositoryInterface.php

A quick look into the contents of BlockRepositoryInterface.php reveals the

following (partial) content:

namespace Magento\Cms\Api;

use Magento\Framework\Api\SearchCriteriaInterface;

interface BlockRepositoryInterface

{

public function save(Data\BlockInterface $block);

public function getById($blockId);

public function getList(SearchCriteriaInterface

$searchCriteria);

public function delete(Data\BlockInterface $block);

public function deleteById($blockId);

}

Code generation

One of the neat features of the Magento application is code generation. Code generation, as implied by its name, generates nonexistent classes. These classes are generated in Magento’s var/generation directory.

One of the neat features of the Magento application is code generation. Code generation, as implied by its name, generates nonexistent classes. These classes are generated in Magento’s var/generation directory.

• bin/magento setup:upgrade: This updates the Magento database schema

and data. While doing this, it truncates the var/di and var/generation

directories.

bin/magento setup:di:compile: This clears the var/generation directory. After doing this, it compiles the code in it again.

bin/magento deploy:mode:set {mode}: This changes the mode from the developer mode to the production mode and vice versa. While doing this,it truncates the var/di, var/generation, and var/view_preprocessed

directories.

bin/magento cache:clean {type}: This cleans the var/cache and var/page_cache directories.

Leave a Comment